<?php
include_once('common/header.php');
if($AppUI->id <=0 || ($AppUI->id > 0 && $AppUI->type < 3)) {
	$this->_redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);
}
$strCode		= $objRequest->getParam('pcode', 0);
$strName		= $objRequest->getParam('pname', 0);
$intPermA		= $objRequest->getParam('pperm_a', 0);
$arrError		= null;
if($strCode == '') $arrError[]	= $arrLocale['code_required'];
if($strCode != '' && !Ecore_Function::isValidCode($strCode)) $arrError[] = $arrLocale['code_format'];
if($strName == '') $arrError[] = $arrLocale['name_required'];
if(!isset($arrError)) {
	if(isset($_SESSION['section_p'])) unset($_SESSION['section_p']);
	if(isset($_SESSION['SECTION_ERROR'])) unset($_SESSION['SECTION_ERROR']);
	$objSection		= new Section();
	$intError		= $objSection->add($strCode, $strName, $intPermA);
	if($intError > 0) $arrError[] = $arrLocale['code_exists'];
	else {		
		$this->_redirect(HOST_BACKEND . 'section');
	}
}
if(isset($arrError)) {
	$_SESSION['SECTION_ERROR']	= $arrError;
	$_SESSION['section_p']		= $objRequest->getParams();	
}
$this->_redirect(HOST_BACKEND.'section/add');
